<?php
/**
 * Created by PhpStorm.
 * User: lhl
 * Date: 2020/10/20
 * Time: 15:37
 * Features: 后台用户
 */

namespace app\adminapiv3\validate;


use think\Validate;

class ServerUserValidate extends Validate
{
    //验证规则
    protected $rule = [
        'id' => 'require|integer|egt:1',
        'group_id' => 'require|integer|egt:1',
        'real_name|用户名' => 'require|max:33',
        'show_name|显示名称' => 'require|max:33',
        'password|密码' => 'require|max:255',
        'password_confirm|确认密码' => 'require|confirm:password|max:255',
        'email|邮箱' => 'email|max:32',
        'login_user_password|当前登录账号的密码' => 'require|max:255',
        'name|账号' => 'require|max:33',
        'captcha|图形验证码' => 'require|max:6',
        'oldPassword|原密码' => 'require|max:255',
        'host_group_id|资产组id' => 'require|integer|egt:1'
    ];

    //错误信息
    protected $message = [
        'role.unique' => '该角色名已存在',
        'password_confirm.confirm' => '两次输入的密码不一致',
        'email.email' => '邮箱格式错误',
        'host_group_id.require' => '请选择所属资产组',
        'host_group_id.integer' => '资产组参数格式错误',
        'host_group_id.egt' => '资产组参数格式错误',
    ];

    //验证场景
    protected $scene = [
        //列表
        'index' => ['group_id'],
        //添加
        'add' => ['group_id','real_name','show_name','password','password_confirm','email','host_group_id'],
        //修改前回显
        'modify_query' => ['id'],
        //修改
        'modify' => ['id','show_name','email','host_group_id'],
        //重置密码
        'resetPassword' => ['id','password','password_confirm','login_user_password'],
        //登录
        'login' => ['name','password','captcha'],
        //修改当前登录用户密码
        'modifyUserPassword' => ['oldPassword','password','password_confirm'],
        //重置超级管理员密码
        'modifyAdmin' => ['password']
    ];

    /**
     * 场景单独验证: 删除后台用户
     */
    public function sceneDel()
    {
        //批量删除支持逗号隔开字符串
        return $this->only(['id'])
            ->remove('id', ['integer','egt'])
            ->append('id','regex:([0-9]+[,]?)+');
    }


}